using DA.AnimGraph;
using OdinSerializer;
using System.Collections.Generic;

namespace DA.AnimGraph.Editor {

    internal class AGANode_SimpleBlend : AGANode_FunctionBase {

        public override AGANodeModelBase modelProperty { set => model = (AGANodeModel_SimpleBlend)value; get => model; }
        [OdinSerialize] AGANodeModel_SimpleBlend model;

        [NodeInputPort("A")] public AUID inputA = new AUID("inputA");
        [NodeInputPort("B")] public AUID inputB = new AUID("inputB");

        public AGANode_SimpleBlend(AGANodeModelBase model) : base(model) {
        }

        public override int Publish(List<PublishNode> outNodes, AGAPublisher.PublishContext context) {
            var pNode = new SimpleBlendPNode();
            pNode.uuid = uuid;
            pNode.data = model.Publish(context);
            var index = outNodes.Count;
            outNodes.Add(pNode);

            var childA = context.subGraph.FindNextNodeInstance(uuid, inputA) as AGANode_FunctionBase;
            if (childA != null) pNode.inputA = AGAPublisher.ExportNode(childA, outNodes, context);
            else pNode.inputA = -1;

            var childB = context.subGraph.FindNextNodeInstance(uuid, inputB) as AGANode_FunctionBase;
            if (childB != null) pNode.inputB = AGAPublisher.ExportNode(childB, outNodes, context);
            else pNode.inputB = -1;

            PublishPerks(pNode, context);
            return index;
        }
    }


    [ModelOf(typeof(AGANode_SimpleBlend))]
    internal class AGANodeModel_SimpleBlend : AGANodeModelBase {

        public AGAFieldModel_FloatLink alpha = new();

        public SimpleBlendNode.SetupData Publish(AGAPublisher.PublishContext context) {
            return new SimpleBlendNode.SetupData() {
                alphaDesc = alpha.Publish(context),
            };
        }
    }


}
